<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta http-equiv="Access-Control-Allow-Origin" content="*">
		<meta http-equiv="content-security-policy">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
		<!-- build:css /css/main.css -->
		<link href="/css/mui.css" rel="stylesheet" />
		<link href="/css/iconfont.css" rel="stylesheet" />
		<link href="/css/common.css" rel="stylesheet" />
		<!-- endbuild -->
		<style>
			.mui-toast-container {
				bottom: 50%;
			}
		</style>

	</head>

	<body>
		<header class="mui-bar mui-bar-nav u-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">我的收藏</h1>
      <span id="to_info" class="mui-icon mui-icon-bars mui-pull-right" onclick="ssdd('#fnav')"></span>
    </header>
    <nav class="mui-bar mui-bar-tab otherNav" id="fnav">
      <a class="mui-tab-item" data-id="index.html" data-url="/index.html">
        <span class="mui-icon iconfont icon-icon-home"></span>
        <span class="mui-tab-label">首页</span>
      </a>
      <a class="mui-tab-item" data-id="category.html" data-url="/category.html">
        <span class="mui-icon iconfont icon-fenlei"></span>
        <span class="mui-tab-label">分类</span>
      </a>
      <a class="mui-tab-item" data-id="search.html" data-url="/search.html">
        <span class="mui-icon iconfont icon-fenleisousuo-home"></span>
        <span class="mui-tab-label">搜索</span>
      </a>
      <a class="mui-tab-item" data-id="cart.html" data-url="/cart.html">
        <span class="mui-icon iconfont icon-gouwuche1"></span>
        <span class="mui-tab-label">购物车</span>
      </a>
      <a class="mui-tab-item" data-id="user.html" data-url="/user/user.html">
        <span class="mui-icon iconfont icon-gerenzhongxin"></span>
        <span class="mui-tab-label">我</span>
      </a>
    </nav>
		<div class="mui-content mui-scroll-wrapper" id="pullrefresh">
			<div class="mui-scroll">
				<ul class="mui-table-view product-list hot-product-list" id="hotProductList">

				</ul>
			</div>
		</div>
		<!-- build:js /js/vendor.js -->
		<script src="/js/mui.min.js"></script>
		<!-- bower:js -->
		<script src="/bower_components/mockjs/dist/mock.js"></script>
		<script src="/bower_components/zepto/zepto.js"></script>
		<script src="/bower_components/Zepto-Cookie/zepto.cookie.js"></script>
		<!--  endbower -->
		<!-- endbuild -->
		<!-- build:js /js/main.js -->
		<script src="/js/common.js"></script>
		<script src="/js/app.js"></script>
		<!-- endbuild -->
		<script>
			var page = 1;
      var tokenVal = $.fn.cookie('token');
      ifLogin(tokenVal);
			function getHotGoods() {
				var flag = false;
				$.ajax({
					url:__BATE__ +'api/customerCollect',
					data:{
					    token: tokenVal,
					page: page
				},
				type:'post',
				success:function(json) {
					if(page <= json.pageAll) {
						if(page == 1) {
							$("#hotProductList").html();
						}
						++page;

						var htmls = '';
						for(var i = 0; i < json.data.length; i++) {
							htmls = htmls + '<li class="mui-table-view-cell mui-media ">' +
								'<img class="mui-img mui-pull-left" src="' + json.data[i].productImage + '">' +
								'<div class="mui-rbox"><a href="#" data-goods="'+json.data[i].product_id+'"><p class="line-num1">' + json.data[i].goods_name + '</p></a>' +
								'<div class="price">' +
								'<span class="money">￥' + json.data[i].price + '</span>		' +
								'</div>' +
								'<span class="qxsc" data-id="'+json.data[i].collect_id+'">取消收藏</span></div>' +
								'<span class="mui-icon iconfont icon-gouwuche" data-stock="'+json.data[i].stock+'" data-goods="'+json.data[i].product_id+'"></span>' +
								'</li>';
						}
						var oldHtml = $("#hotProductList").html();
						$("#hotProductList").html(oldHtml + htmls);

					} else {
						flag = true;
					}

					try {
						mui('#pullrefresh').pullRefresh().endPullupToRefresh(flag);
					} catch(e) {}

				}
				});
			}


			(function(mui, doc) {
				mui.init({
					statusBarBackground: '#ffffff',
					pullRefresh: {
						container: "#pullrefresh",
						up: {
							contentup: "上拉加载",
							contentrefresh: "正在加载...",
							contentnomore: '没有更多数据',
							callback: function() {
								getHotGoods();
							}
						}
					}
				});

				mui.ready(function() {
					$(document).on('tap', '.qxsc', function(e) {
						var asd = $(this).parents('.mui-media');
						var id = $(this).attr('data-id');
						e.detail.gesture.preventDefault(); //修复iOS 8.x平台存在的bug，使用plus.nativeUI.prompt会造成输入法闪一下又没了
						var btnArray = ['否', '是'];
						mui.confirm('确定取消关注吗？', '', btnArray, function(e) {
							if(e.index == 1) {
                $.ajax({
                  url: __BATE__ + 'api/cancelCollect',
                  type: 'post',
                  data: {
                    collect_id: id,
                    token: tokenVal
                  },
                  success: function(json) {
                    if(json.ret_msg == true){
                      asd.remove();
                    }
                  }
                })

							}
						})
					});

					$(document).on('tap', '.icon-gouwuche', function(e) {
					    var goodsId = $(this).attr('data-goods');
					    var kucun = $(this).attr('data-stock');
            if(kucun <= 0) {
              stip('没货啦~请持续关注 ！');
              return;
            }
            $.ajax({
              url: __BATE__ + 'api/addToCart',
              data: {
                id: goodsId,
                qty: 1,
                token: tokenVal
              },
              type: 'post',
              success: function(json) {
                if(json.ret_msg == true) {
                  stip('恭喜，已添加至购物车！')

                } else if(json.ret_msg == "用户未登录") {
                  stip(json.ret_msg);
                  setTimeout(function() {
                    toLoginView();
                  }, 1000)
                } else if(json.ret_msg == "token验证无效或已过期") {
                  stip(json.ret_msg);
                  setTimeout(function() {
                    toLoginView();
                  }, 1000)
                } else {
                  stip(json.ret_msg);
                }
              }
            });

					});

					getHotGoods();
				});

			}(mui, document));
		</script>
	</body>

</html>
